import matplotlib.pyplot as plt
from keras import Sequential
from keras.datasets import boston_housing
from keras.layers import Dense

(x_train, y_train), (x_test, y_test) = boston_housing.load_data()

mean = x_train.mean(axis=0)
std = x_train.std(axis=0)
x_train = (x_train - mean) / std

mean = x_test.mean(axis=0)
std = x_test.std(axis=0)
x_test = (x_test - mean) / std

model = Sequential()
model.add(Dense(64, activation="relu", input_shape=(x_train.shape[1],)))
model.add(Dense(64, activation="relu"))
model.add(Dense(1))

model.compile(loss="mse", metrics=['mse'])

bath = 32
epoch = 1000
split1 = 0.01

model.fit(x_train, y_train, batch_size=bath, epochs=epoch, validation_split=split1)
score = model.evaluate(x_test, y_test)
print(score)

y_pre = model.predict(x_test)
plt.plot(y_pre, color="red")
plt.plot(y_test, color="green")
plt.legend(['y_pre', 'y_test'])
plt.show()